//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:20-4-14
// @Time:上午11:09
//

#ifndef TESTSERVER_IOTBUSINESS_H
#define TESTSERVER_IOTBUSINESS_H

#include <stdint.h>
#include <handy/handy.h>

#include "BaseBusiness.h"

using namespace handy;

class IoTBusiness : public BaseBusiness
{
private:
    std::map<int, EventFunction> eventMap;
public:
    friend BaseBusiness;

    IoTBusiness();

    virtual ~IoTBusiness();

//    IoTBusiness( int type_sub, int taskid, const TcpConnPtr &con, uint8_t *protoData, int datalen, void *userdata = nullptr);
    int dispatchEvents(
            int type_sub,
            int taskid,
            const TcpConnPtr &con,
            uint8_t *protoData,
            int datalen,
            void *userdata) override;

    void setEvents() override;

private:
    static int LoginDevice(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int FindGateway(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int CreateDevice(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int FindDeviceToken(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int FindMyDevices(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int GenerateDeviceToken(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int DeviceHeartBeat(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int UploadSensor(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int FindSensor(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int ControlDevice(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);

    static int ControlDeviceAck(EventContext *context, uint8_t *protoData, int datalen, void *userdata = nullptr);


};


#endif //TESTSERVER_IOTBUSINESS_H
